<%-- 
    Document   : excelInsert
    Created on : May 2, 2012, 2:17:59 PM
    Author     : Brian
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="Servlet.dataBaseController"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.BufferedInputStream"%>
<%@page import="java.io.DataInputStream"%>
<%@page import="java.io.File"%>
<%@page import="com.mysql.jdbc.Connection"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.io.IOException"%>
<%@page contentType="text/html" pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
        <title>JSP Page</title>
    </head>
    <body>
        <%
Connection con1=dataBaseController.getConnection();
Statement st=con1.createStatement();
Statement st1=con1.createStatement();
Statement st2=con1.createStatement();

String filename=config.getServletContext().getRealPath("/")+"excel/YHOO.csv";

DataInputStream dis = null;
String record = null;
int recCount = 0;
if(filename!=null)
{
try {
File f = new File(filename);
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
ArrayList contents=new ArrayList();
while ( (record=dis.readLine()) != null )
{

contents.add(record);

}

for(int i=1;i<contents.size();i++)
{
String[] val2=new String[23];
String[] val1=contents.get(i).toString().split(",");
String em="";
for(int k=0;k<val1.length;k++)
{
if(val1[k].substring(0,1).equals("\"")||val1[k].substring(0,1).equals("'"))
{
val2[k]=val1[k].substring(1,(val1[k].length())-1);
out.println(val2[k]);
}
else
{
val2[k]=val1[k];
}
}
String[] temp=val2[0].split("/");
if(Integer.parseInt(temp[0])<10)
    temp[0]="0"+temp[0];
if(Integer.parseInt(temp[1])<10)
    temp[1]="0"+temp[1];
st.execute("insert into stockhistory(stockid,Date,pricepershare) values('YHOO','"+temp[2]+"-"+temp[0]+"-"+temp[1]+"','"+val2[1]+"')");

%>
<br>
<%
}
}
catch (IOException e) {
out.println("Exception error!" + e.getMessage());

}
}
%>
    </body>
</html>
